package com.jd.sentinelspringboot;

import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;


/**
 * sentinel dashboard地址
 * -Denv=DEV  -Dcsp.sentinel.dashboard.server=consoleIp:port
 * -Dcsp.sentinel.dashboard.server=consoleIp:port
 * -Dproject.name=apollo-demo
 */
@EnableApolloConfig   //开启apollo客户端注解
@SpringBootApplication
public class SentinelSpringbootApplication {

    public static void main(String[] args) {
        SpringApplication.run(SentinelSpringbootApplication.class, args);
//        initFlowRules2();
//        System.out.println("规则初始化完毕");
    }

    public static void initFlowRules2(){
        List<FlowRule> rules = new ArrayList<FlowRule>();
        FlowRule rule = new FlowRule();
        //注意： 我们的规则一定要绑定到对应的资源上，通过资源名称进行绑定
        rule.setResource("HelloWorld");
        rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
        // Set limit QPS to 20.
        rule.setCount(20);
        rules.add(rule);
        //规则管理器
        FlowRuleManager.loadRules(rules);
    }
}
